﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Hybrid;

namespace Hybrid
{
    public partial class Start : Form
    {
        ColorHandler ch = new ColorHandler();
        string[] args = Environment.GetCommandLineArgs();
        public Start()
        {
            InitializeComponent();
            
            
        }

        private void Start_Load(object sender, EventArgs e)
        {
            if (args.Length > 1)
            {
                LoadFile(args[1]);
                this.Hide();
            }

            label2.Text = "Game Engine && UI: Matthew Little";
            label3.Text = "Bitmaps && Animation: Aaron Nakashima";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "DII files (*.dii)|*.dii";
            open.InitialDirectory = Application.StartupPath + "\\Saves";
            open.Title = "Select Game Save";
            if (open.ShowDialog() == DialogResult.OK)
            {
                LoadFile(open.FileName);
            }
        }

        void LoadFile(string FilePath)
        {
            string[] values = File.ReadAllText(FilePath).Split(',');
            string[] scores = values[2].Split('~');

            List<int> listscores = new List<int>();
            for (int i = 0; i < scores.Length; i++)
            {
                listscores.Add(System.Convert.ToInt32(scores[i]));
            }

            Main loadFrm = new Main(System.Convert.ToInt32(values[1]), System.Convert.ToInt32(values[0]), listscores.ToArray(), false, false);
            loadFrm.Show();
            loadFrm.FormClosing += new FormClosingEventHandler(ChildFormClosing);
            this.Hide();
            timer1.Stop();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SelectPlayers sp = new SelectPlayers();
            sp.FormClosing += new FormClosingEventHandler(ChildFormClosing);
            sp.Show();
            this.Hide();
            timer1.Stop();
        }

        void ChildFormClosing(object sender, FormClosingEventArgs e)
        {
            this.Show();
            timer1.Start();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            NetworkStart ns = new NetworkStart();
            ns.FormClosing += new FormClosingEventHandler(ChildFormClosing);
            ns.Show();
            this.Hide();
            timer1.Stop();
        }


        int h = 0;
        bool up = true;

        private void timer1_Tick(object sender, EventArgs e)
        {
            
            if (up)
            {
                h++;
                if (h == 360) up = false;
            }
            else
            {
                h--;
                if (h == 0) up = true;
            }
            label1.ForeColor = ColorHandler.HSVtoColor(360 - h, 100, 100);

            this.BackColor = ColorHandler.HSVtoColor(h, 100, 70);
        }


    }
}
